﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using WebMinhHang.Libs;
using WebMinhHang.Lists;

namespace WebMinhHang
{
    public partial class FrmThongKeHoaDonKhongLuu : System.Web.UI.Page
    {
        public int _SoLuong = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    string dbName = lstDsDatabase.SelectedValue;
                    Connection.ConnectString(dbName);

                    cmbKyBaoCao.SelectedIndex = 17;
                    dateNgayBatDau.Enabled = true;
                    dateNgayKetThuc.Enabled = true;
                    DateTime now = DateTime.Now;
                    dateNgayBatDau.Date = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
                    dateNgayKetThuc.Date = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
                }
            }
            catch (Exception ex)
            {
                string display = ex.Message;
                ClientScript.RegisterStartupScript(this.GetType(), "Thông báo", "alert('" + display + "');", true);
            }

        }

        protected void cmbKyBaoCao_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                ThoiDiemBaoCao.ThietLapKhoangThoiGianBaoCao(cmbKyBaoCao.Text, cmbKyBaoCao, dateNgayBatDau, dateNgayKetThuc);
            }
            catch (Exception ex)
            {
                string display = ex.Message;
                ClientScript.RegisterStartupScript(this.GetType(), "Thông báo", "alert('" + display + "');", true);
            }
        }

        protected void btnThongKe_Click(object sender, EventArgs e)
        {
            try
            {
                string filterExpress = @"TanNgu like N'%mà không lưu%'";
                DataTable danhSach = DanhMucNhatKySuDung.Instance.GetHoaDonKhongLuu(dateNgayBatDau.Date, dateNgayKetThuc.Date);
                gridResult.DataSource = danhSach;
                gridResult.DataBind();

                _SoLuong = danhSach.Rows.Count;
            }
            catch (Exception ex)
            {
                string display = ex.Message;
                ClientScript.RegisterStartupScript(this.GetType(), "Thông báo", "alert('" + display + "');", true);
            }
            finally
            {
            }
        }

        protected void lstDsDatabase_SelectedIndexChanged(object sender, EventArgs e)
        {
            string dbName = lstDsDatabase.SelectedValue;
            Connection.ConnectString(dbName);

            gridResult.DataSource = null;
            gridResult.DataBind();
        }
    }
}
